package ar.fiuba.tp7552.buildadmin.webactions.users;

import java.util.Collection;

import ar.fiuba.tp7552.buildadmin.model.auth.User;
import ar.fiuba.tp7552.buildadmin.model.builds.Edificio;
import ar.fiuba.tp7552.buildadmin.service.EdificioService;
import ar.fiuba.tp7552.buildadmin.service.PermissionService;
import ar.fiuba.tp7552.buildadmin.service.UserService;
import ar.fiuba.tp7552.buildadmin.util.ResultRow;
import ar.fiuba.tp7552.buildadmin.webactions.BaseAction;

import com.opensymphony.xwork2.Preparable;

public class ListPermissionAction extends BaseAction implements Preparable {
	
	private PermissionService permService;
	private UserService userService;
	private EdificioService edifService;
	private User user;
	private Collection<ResultRow> permissions;
	
	// ~~ Constructor ====================================================
	
	public ListPermissionAction(UserService userService, EdificioService edifService, PermissionService permService) {
		super();
		this.userService = userService;
		this.edifService = edifService;
		this.permService = permService;
	}
	
	/**
	 * Obtiene de la db el usuario si corresponde.
	 */
	@Override
	public void prepare() {
		if (user != null && user.getId() != null) {
			user = userService.getUser(user.getId());
			permissions = permService.getAll(user);
		}
	}
	
	public String getAll() {
		return BaseAction.SUCCESS;
	}
	
	// ~~ getters y setters ==============================================

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Collection<ResultRow> getPermissions() {
		return permissions;
	}
	
	public Collection<Edificio> getEdificios() {
		return edifService.getAll();
	}

}
